from pymongo import MongoClient
import json

with open('../config.py', 'r') as f:
    exec(f.read())

conn_ = MongoClient(mongoinfo['ip'], mongoinfo['port'])

capture_ = conn_.guidang4.capture

# # RUN1mongo
# repo_man_ = conn_.face_platform.repo_man
# RUN1mongo 分离
conn1_ = MongoClient(yituinfo['ip'], 27017)
repo_man_ = conn1_.face_platform.repo_man


# run_mongo_ = conn_.guidang4.run_mongo
runmongo_time_ = conn_.guidang4.runmongo_time


def update_time(max_time):
    runmongo_time_.update_one({'_id': 'run1_mongo_time'}, {'$set': {'update_time': max_time}}, upsert=True)

def get_time():
    return runmongo_time_.find_one({'update_time': {'$exists': True}})

def insert_cap(dic):
    id = dic.pop('_id')

    return capture_.update_one({'_id': id}, {'$set': dic}, upsert=True)

def update_ovo(face_image_id, ovo_f):
    return capture_.update_one({'_id': face_image_id}, {'$set': {'ovo_f': ovo_f}}, upsert=True)
